package bubuntux.jusbscan.core;

import java.io.File;

import bubuntux.jusbscan.tui.Frame;

public class Terminal extends Thread {

	private Antivirus antivirus = null;
	private Frame frame = null;
	private File dir = null;

	public Terminal(String some) {
		super();
		this.antivirus = Antivirus.load();
		this.frame = new Frame();
	}

	public Frame getFrame() {
		return this.frame;
	}

	@Override
	public void run() {
		dir = new File("/home/bubuntux/Pictures");
		if (antivirus.scan(dir)) {
			this.frame.totalFiles(Configs.getFilesCount(dir.getAbsolutePath()));
			antivirus.bufferResult();
			while (antivirus.finish() == false) {
				if (antivirus.isNewFile()) {
					this.frame.sumProgressBar();
				}
				this.frame.setInfo(antivirus.getActualFile());
				this.frame.addResume(antivirus.getVirusFiles());
				antivirus.bufferResult();
			}
			this.frame.setInfo("Please, unplug the USB");
			this.frame.addResume(antivirus.getVirusFiles());

			while (true) { // TODO unplug USB
				Configs.beep();
				try {
					Terminal.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
